/*
 * Copyright 2009 BioTeam Inc
 * 
 * Licensed under License GNU LESSER GENERAL PUBLIC LICENSE version 3.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.gnu.org/copyleft/lesser.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package net.bioteam.appweb.submit;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.Reader;

import junit.framework.TestCase;

public class FastaSplitTester extends TestCase
{

	protected void setUp() throws Exception
	{
		super.setUp();
	}

	protected void tearDown() throws Exception
	{
		super.tearDown();
	}
	
	public void testSplit() throws Exception
	{
		Reader reader=new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("net/bioteam/appweb/submit/seq1.txt"));
		File target=new File("target");
		int splits=BtbatchPreprocessor.splitInputs(reader, target, 3);
		assertEquals(2, splits);
		for (int i=1; i<=2; i++)
		{
			assertTrue(new File("target"+File.separator+i).exists());
			new File("target"+File.separator+i).delete();
		}
		reader.close();
		
		reader=new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("net/bioteam/appweb/submit/seq1.txt"));
		splits=BtbatchPreprocessor.splitInputs(reader, target, 2);
		assertEquals(3, splits);
		for (int i=1; i<=3; i++)
		{
			assertTrue(new File("target"+File.separator+i).exists());
			new File("target"+File.separator+i).delete();
		}
		reader.close();
		
		reader=new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("net/bioteam/appweb/submit/seq1.txt"));
		splits=BtbatchPreprocessor.splitInputs(reader, target, 6);
		assertEquals(1, splits);
		for (int i=1; i<=1; i++)
		{
			assertTrue(new File("target"+File.separator+i).exists());
			new File("target"+File.separator+i).delete();
		}
		
		
		reader.close();
		reader=new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("net/bioteam/appweb/submit/seq1.txt"));

		splits=BtbatchPreprocessor.splitInputs(reader, target, 7);
		assertEquals(1, splits);
		for (int i=1; i<=1; i++)
		{
			assertTrue(new File("target"+File.separator+i).exists());
			new File("target"+File.separator+i).delete();
		}

		reader.close();
		reader=new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream("net/bioteam/appweb/submit/seq1.txt"));

		splits=BtbatchPreprocessor.splitInputs(reader, target, 5);
		assertEquals(2, splits);
		for (int i=1; i<=2; i++)
		{
			assertTrue(new File("target"+File.separator+i).exists());
			new File("target"+File.separator+i).delete();
		}
		
		reader.close();
		reader=new BufferedReader(new FileReader("D:/shareforvm/linux/batchblast.txt"));
		splits=BtbatchPreprocessor.splitInputs(reader, target, 3);
		assertEquals(7, splits);
//		for (int i=1; i<=7; i++)
//		{
//			assertTrue(new File("target"+File.separator+i).exists());
//			new File("target"+File.separator+i).delete();
//		}
		
	}

}
